<?php 
global $frontpage_cloudcarousel;
?>
<?php foreach($gallery as $val){ ?>
		<?php $link = ''; ?>
		<?php $meta = get_post_meta($val->ID, $frontpage_cloudcarousel->get_the_id(), TRUE);  ?>
		<?php 
			if( $meta['select_post'] != '-2' ){ 
				$link = get_permalink( $meta['select_post'] );
			}elseif( $meta['select_post'] == '-2' ){
				$link = $meta['external_link'];
			} 
		?>
		<a href="<?php echo $link;?>" target="_blank">
			<?php
				echo get_the_post_thumbnail($val->ID,'full', array('class' => 'cloudcarousel'));
			?>	
		</a>
<?php } ?>